<?php
/**
* Yii jsStyledAlert widget
* Widget replaces javascript alert() function to its own, that you can stylize by html & css
* 
* 
* ===Installation===
* Just put jsStyledAlert directory to yor extensions_dir /widgets (/protected/extensions/widgets).
* If you wont to use themes, just place jsStyledAlert/views to themes/<your_theme>/views/EJsStyledAlertWidget
* 
* ===Usage===
* Just place:
* <?$this->widget('ext.widgets.jsStyledAlert.EJsStyledAlertWidget');?>
* to your layout file somewhere inside "BODY" tag.
* 
* ===Stylizing===  
* Edit files in protected/extensions/widgets/jsStyledAlert/views/ (or in themes/<your_theme>/views/EJsStyledAlertWidget if you use themes):
* html: jsStyledAlertHtml.php
* css: assets/StyledAlert.css
* js: assets/StyledAlert.js
* If you wont to use images, put them to assets directory & include in html using $assetPath in SRC attribute: <IMG SRC='<?=$assetPath>/img/image1.jpg'>
* To define backgroud-image in css, use relative paths.
* 
* Preserve element id's when you edit html, else you will need to correct js
* 
* 
* 
* @author Vitaliy Stepanenko <mail@vitaliy.in>
* @version 1.0.1
* 08.11.2010
*/
class EJsStyledAlertWidget extends CWidget {
    
    protected function publishAssets()
    {
       if(($theme=Yii::app()->getTheme())!==null){
           $className=str_replace('\\','_',ltrim(get_class($this),'\\')); // possibly namespaced class
           $path=$theme->getViewPath().DIRECTORY_SEPARATOR.$className;
           if (!is_dir($path)) $path = $this->getViewPath();
       }else{
           $path=$this->getViewPath();
       } 
       return Yii::app()->assetManager->publish(
            $path . DIRECTORY_SEPARATOR . 'assets',
            false,
            -1,
            YII_DEBUG
       );             
    }

    /**
    * Render widget html, publish assets & include scripts/css
    * 
    */
    public function run() {                                     
        $assetUrl=$this->publishAssets();
        Yii::app()->clientScript
            ->registerCoreScript('jquery')  
            ->registerCssFile($assetUrl.'/StyledAlert.css')         
            ->registerScriptFile($assetUrl.'/StyledAlert.js',CClientScript::POS_HEAD);   
            
        $this->render('jsStyledAlertHtml',array('assetUrl'=>$assetUrl));   
    }
}